package zifu;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

public class copu11111111111 {
    public static void main(String[] args) {
        File sourceDirectory = new File("D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay13\\src\\main\\java\\zifu\\demo");
        File destinationDirectory = new File("D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay13\\src\\main\\java\\zifu\\demo2");

        try {
            copyDirectory(sourceDirectory, destinationDirectory);
            System.out.println("Directory copied successfully!");
        } catch (IOException e) {
            System.out.println("Failed to copy directory!");
            e.printStackTrace();
        }
    }
    public static void copyDirectory(File source, File destination) throws IOException {
        if (!destination.exists()) {
            destination.mkdirs();
        }

        for (File file : source.listFiles()) {
            File destFile = new File(destination, file.getName());
            if (file.isDirectory()) {
                copyDirectory(file, destFile);
            } else {
                Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }
}
